<template>
  <div>
    <template v-for="(item, index) in projectParameters">
      <div :key="index">
        <KFormItem
          :ref="item.model"
          @change="handleChange"
          :disabled="disabled"
          :dynamicData="dynamicData"
          :record="item"
          :formConfig="formConfig"
          :config="config"
          :initValue="getValue(item.model)"
        />
      </div>
    </template>
  </div>
</template>
<script>
import KFormItem from "@/visualization/KFormItem/index";
export default {
  name: "projectParameters",
  props: ["projectParameters"],
  components: {
    KFormItem
  },
  data() {
    return {
      items: [],
      data:{},
      value:true,
      dynamicData: {},
      id:0,
      formConfig: {},
      config: {},
      disabled:false
    };
  },
  methods:{
    getValue(field){
      return this.data[field];
    },
    handleInput(field,value){
      debugger;

      this.data[field] = document.getElementById(field).value;
      console.log('data[field]:'+ this.data[field]);
    },
    onSwitch(field,value){
      debugger;
      this.data[field]=document.getElementById(field).checked;
      // console.log('this.data:'+this.data);
      console.log('data[field]:'+ this.data[field]);
    },
    getPropertiesValue(){
      var jsonStr = JSON.stringify(this.data);
      console.log('retun json str:'+jsonStr);
      var retJson = JSON.parse(jsonStr);
      return retJson;
    },
    setPropertiesValue(propertiesData){
      var array_list=this.$refs;
      if(propertiesData!=null) {
        for (var key in array_list) {
          console.log(array_list[key]);
          if (propertiesData[key]) {
            if(array_list[key][0]) {
              debugger;
              array_list[key][0].setValue(propertiesData[key]);
            }
          }else{
            if(array_list[key][0]){
              array_list[key][0].setValue('');
            }
          }
        }
      }
      if(propertiesData==null){
        this.data = {};
      }else{
        this.data = propertiesData;
      }
      console.log('set json str:'+JSON.stringify(this.data));
    },
    handleChange(value, key) {
       debugger;
      this.data[key] = value;
    }
  },
  mounted(){
    this.data = {};
    //debugger;
    //填写默认值
    var i;
    for(i=0;i<this.projectParameters.length;i++){
      var item = this.projectParameters[i];
      if(item.options.defaultValue){
        this.data[item.model]=item.options.defaultValue;
      }
    }
  }
};
</script>

<style scoped></style>
